import { createRouter, createWebHashHistory } from 'vue-router'
import Layout from '@/layouts/index.vue'

// 路由配置
export const routes = [
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    meta: { hidden: true }
  },
  
  // 战术面板 - 独立显示，不在分组中
  {
    path: '/dashboard',
    component: Layout,
    meta: { 
      title: '战术面板', 
      icon: 'Odometer',
      single: true
    },
    children: [
      {
        path: '',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index.vue'),
        meta: { title: '战术面板', icon: 'Odometer' }
      }
    ]
  },
  
  // 核心功能模块 - 靶场场景
  // {
  //   path: '/scene',
  //   component: Layout,
  //   redirect: '/scene/list',
  //   meta: { 
  //     title: '靶场场景', 
  //     icon: 'Platform',
  //     group: '核心功能模块'
  //   },
  //   children: [
  //     {
  //       path: 'list',
  //       name: 'SceneList',
  //       component: () => import('@/views/scene/list/index.vue'),
  //       meta: { title: '靶标场景', icon: 'List' }
  //     },
  //     {
  //       path: 'detail',
  //       name: 'SceneDetail',
  //       component: () => import('@/views/scene/index.vue'),
  //       props: (route) => ({
  //         ...route.query,
  //         _timestamp: Date.now()
  //       }),
  //       meta: {
  //         hidden: true,
  //         title: '场景详情',
  //         icon: 'View'
  //       }
  //     },
  //     {
  //       path: 'create-tactical',
  //       name: 'CreateTactical',
  //       component: () => import('@/views/scene/create-tactical.vue'),
  //       props: (route) => ({
  //         ...route.query,
  //         _timestamp: Date.now()
  //       }),
  //       meta: {
  //         hidden: true,
  //         title: '创建战术',
  //         icon: 'Plus'
  //       }
  //     }
  //   ]
  // },

    // 核心功能模块 - 战术拓扑管理
    {
      path: '/tactical-topo',
      component: Layout,
      redirect: '/tactical-topo/list',
      meta: { 
        title: '战术拓扑管理', 
        icon: 'Setting',
        group: '核心功能模块'
      },
      children: [
        {
          path: 'list',
          name: 'TacticalTopoList',
          component: () => import('@/views/tactical-env/index.vue'),
          meta: { title: '战术拓扑管理', icon: 'List' }
        },
        // {
        //   path: 'create',
        //   name: 'TacticalTopoCreate',
        //   component: () => import('@/views/tactical-env/create.vue'),
        //   meta: { title: '创建拓扑', icon: 'Plus' }
        // }
      ]
    },

  // 核心功能模块 - 场景管理
  {
    path: '/scene-management',
    component: Layout,
    redirect: '/scene-management/overview',
    meta: { 
      title: '场景管理', 
      icon: 'Management',
      group: '核心功能模块'
    },
    children: [
      {
        path: 'overview',
        name: 'SceneOverview',
        component: () => import('@/views/scene-management/overview.vue'),
        meta: { title: '场景概览', icon: 'DataBoard' }
      },
      {
        path: 'create',
        name: 'SceneCreate',
        component: () => import('@/views/scene-management/create.vue'),
        meta: { title: '场景创建', icon: 'Plus' }
      },
      {
        path: 'edit',
        name: 'SceneEdit',
        component: () => import('@/views/scene-management/edit.vue'),
        meta: { title: '场景编辑', icon: 'Edit' }
      },
      {
        path: 'import',
        name: 'SceneImport',
        component: () => import('@/views/scene-management/import.vue'),
        meta: { title: '场景导入', icon: 'Upload' }
      }
    ]
  },
  
  // 直接访问创建战术页面（用于测试）
  {
    path: '/create-tactical',
    name: 'CreateTacticalDirect',
    component: () => import('@/views/scene/create-tactical.vue'),
    props: (route) => ({
      ...route.query,
      _timestamp: Date.now()
    }),
    meta: {
      title: '创建战术',
      icon: 'Plus',
      hidden: true
    }
  },
  
  
  // 核心功能模块 - 战术方案管理
  {
    path: '/tactical-plan',
    component: Layout,
    redirect: '/tactical-plan/list',
    meta: { 
      title: '战术方案管理', 
      icon: 'Document',
      group: '核心功能模块'
    },
    children: [
      {
        path: 'list',
        name: 'PlanList',
        component: () => import('@/views/tactical-plan/list.vue'),
        meta: { title: '方案列表', icon: 'List' }
      },
      {
        path: 'simulation',
        name: 'PlanSimulation',
        component: () => import('@/views/tactical-plan/simulation.vue'),
        meta: { title: '战术方案推演', icon: 'VideoPlay' }
      },
      {
        path: 'detail/:id',
        name: 'PlanDetail',
        component: () => import('@/views/tactical-plan/detail.vue'),
        meta: { title: '方案详情', hidden: true }
      }
    ]
  },
  
  // 核心功能模块 - 战术资源管理
  {
    path: '/tactical-resource',
    component: Layout,
    redirect: '/tactical-resource/bus',
    meta: { 
      title: '战术资源管理', 
      icon: 'Files',
      group: '核心功能模块'
    },
    children: [
      {
        path: 'bus',
        name: 'BusManagement',
        component: () => import('@/views/bus/index.vue'),
        meta: { title: '总线管理', icon: 'Connection' }
      },
      {
        path: 'attack-methods',
        name: 'AttackMethods',
        component: () => import('@/views/attack-techniques/index.vue'),
        meta: { title: '攻击方法', icon: 'Tickets' }
      },
      {
        path: 'topo-devices',
        name: 'TopoDevices',
        component: () => import('@/views/tactical-resource/topo-devices.vue'),
        meta: { title: '设备管理', icon: 'Monitor' }
      }
    ]
  },
  
  // 分析与管理模块 - 战术报告管理
  {
    path: '/tactical-report',
    component: Layout,
    redirect: '/tactical-report/list',
    meta: { 
      title: '战术报告管理', 
      icon: 'DocumentAdd',
      group: '分析与管理模块'
    },
    children: [
      {
        path: 'list',
        name: 'TacticalReportList',
        component: () => import('@/views/tactical-report/index.vue'),
        meta: { title: '战术报告管理', icon: 'List' }
      },
      // {
      //   path: 'create',
      //   name: 'TacticalReportCreate',
      //   component: () => import('@/views/tactical-report/create.vue'),
      //   meta: { title: '创建报告', icon: 'EditPen' }
      // }
    ]
  },
  
  // 分析与管理模块 - 战术回顾
  {
    path: '/tactical-review',
    component: Layout,
    meta: { 
      title: '战术回顾', 
      icon: 'Refresh',
      single: true,
      group: '分析与管理模块'
    },
    children: [
      {
        path: '',
        name: 'TacticalReview',
        component: () => import('@/views/tactical-review/index.vue'),
        meta: { title: '战术回顾', icon: 'Refresh' }
      }
    ]
  },
  
  // 分析与管理模块 - 漏洞信息管理
  {
    path: '/vulnerability-list',
    component: Layout,
    meta: { 
      title: '漏洞信息管理', 
      icon: 'WarningFilled',
      single: true,
      group: '分析与管理模块'
    },
    children: [
      {
        path: '',
        name: 'VulnerabilityList',
        component: () => import('@/views/vulnerability/index.vue'),
        meta: { title: '漏洞信息管理', icon: 'List' }
      }
    ]
  },
  
  // 分析与管理模块 - ATT&CK管理
  {
    path: '/attack-list',
    component: Layout,
    meta: { 
      title: 'ATT&CK管理', 
      icon: 'Compass',
       single: true,
      group: '分析与管理模块'
    },
    children: [
      {
        path: 'list',
        name: 'AttackList',
        component: () => import('@/views/attack-techniques/index.vue'),
        meta: { title: 'ATT&CK管理', icon: 'List' }
      },
    ]
  },
  
  // 分析与管理模块 - 日志管理
  {
    path: '/log',
    component: Layout,
    meta: { 
      title: '日志管理', 
      icon: 'Notebook',
      single: true,
      group: '分析与管理模块'
    },
    children: [
      {
        path: '',
        name: 'LogManagement',
        component: () => import('@/views/log/index.vue'),
        meta: { title: '日志管理', icon: 'Notebook' }
      }
    ]
  },
  
  // 分析与管理模块 - 数据表管理
  {
    path: '/data-table',
    component: Layout,
    meta: { 
      title: '数据表管理', 
      icon: 'Grid',
      single: true,
      group: '分析与管理模块'
    },
    children: [
      {
        path: '',
        name: 'DataTableManagement',
        component: () => import('@/views/data-table/index.vue'),
        meta: { title: '数据表管理', icon: 'Grid' }
      }
    ]
  }
]

// 创建路由实例
const router = createRouter({
  history: createWebHashHistory(),
  routes,
})

// 路由前置守卫
router.beforeEach((to, from, next) => {
  // 设置页面标题
  document.title = to.meta.title || '战术方案设计系统'
  next()
})

export default router 